//
//  JPAudioViewController.m
//  GC_OC
//
//  Created by Kris on 2023/4/27.
//

#import "JPAudioViewController.h"
#import "SUPlayerManager.h"
#import "SURateAlertVC.h"
#import "SUMarkCell.h"
#import "SUSlider.h"
#import "UIImage+HSAddtions.h"
#import "AudioViewController.h"


@interface JPAudioViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) SUPlayerManager * player; //播放器类
@property (nonatomic, strong) NSTimer * timer;          //界面刷新定时器
@property (nonatomic, strong) NSTimer * timer1;         //闹钟定时器


@property (weak, nonatomic) IBOutlet UILabel *durationTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalTimeLabel;
@property (weak, nonatomic) IBOutlet UIButton *lastBtn;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;
@property (weak, nonatomic) IBOutlet UIButton *rateBtn;
@property (weak, nonatomic) IBOutlet UIButton *modeBtn;
@property (weak, nonatomic) IBOutlet UIButton *clockBtn;


@property (weak, nonatomic) IBOutlet UIProgressView *cacheProgressView;
@property (weak, nonatomic) IBOutlet SUSlider *slider;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UITextView *desTV;

@property (weak, nonatomic) IBOutlet UILabel *m1Label;
@property (weak, nonatomic) IBOutlet UIView *markView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *markViewHeight;

@property (weak, nonatomic) IBOutlet UILabel *m2Label;
@property (weak, nonatomic) IBOutlet UIView *affixView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *affixViewHeight;

@property (weak, nonatomic) IBOutlet UIView *fastView;
@property (weak, nonatomic) IBOutlet UILabel *f1Label;
@property (weak, nonatomic) IBOutlet UILabel *f2Label;

@property (weak, nonatomic) IBOutlet UILabel *djsLabel;// 倒计时


@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionView *collectionView1;


@property (nonatomic, assign) BOOL isSliding;
@property (nonatomic, assign) CGFloat sliderValue;
@end

@implementation JPAudioViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    
    self.player = [SUPlayerManager manager];

    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.markView);
    }];
    [self.collectionView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.affixView);
    }];
    
    [self setupUIData];
    
    if (self.player.status == SUPlayStatusPlay) {
        [self.playBtn setImage:[UIImage imageNamed:@"icon_stopImg"] forState:0];
    } else {
        [self.playBtn setImage:[UIImage imageNamed:@"icon_playImg"] forState:0];
    }
    
    if (self.player.mode == SUModeOrder) {
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"顺序播放"] forState:0];
    } else if (self.player.mode == SUModeSingle) {
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"单曲播放"] forState:0];
    } else if (self.player.mode == SUModeRandom) {
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"随机播放"] forState:0];
    }
    
    if ([self.player.saveClock isEqualToString:@"播完当前媒体再关闭"] || [self.player.saveClock isEqualToString:@"不开启"]) {
        self.djsLabel.hidden = YES;
        [self.timer1 setFireDate:[NSDate distantFuture]];
    } else {
        self.djsLabel.hidden = NO;
        self.timer1 = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownSet) userInfo:nil repeats:YES];
    }
    
    
    NSString *rateStr = [self getImageNameWithRate:[NSString stringWithFormat:@"%f", self.player.saveRate]];
    [self.rateBtn setBackgroundImage:[UIImage imageNamed:rateStr] forState:0];

    self.slider.minimumTrackTintColor = ColorFromHex(0x0091FF);
    self.slider.maximumTrackTintColor = [UIColor clearColor];
    self.slider.continuous = YES;

    //滑条的滑动-触摸到滑块
    [self.slider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
    //滑条的滑动-抬起手指触摸结束
    [self.slider addTarget:self action:@selector(sliderTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    //滑条的滑动-滑块的位置改变
    [self.slider addTarget:self action:@selector(sliderTouchValueChanged:) forControlEvents:UIControlEventValueChanged];
    
    [self addTimer];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertFunc) name:@"noNext" object:nil];;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertFunc1) name:@"noLast" object:nil];;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertFunc2) name:@"autoPlay" object:nil];;

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:true];
}
- (void)setupUIData
{
    if ([SUPlayerManager manager].saveBufferProgress == 1.0f) {
        [self.slider setThumbImage:[UIImage imageNamed:@"icon_slidBtnGreen"] forState:UIControlStateNormal];
    } else {
        [self.slider setThumbImage:[UIImage imageNamed:@"icon_slidBtn"] forState:UIControlStateNormal];
    }
    
    if ([SUPlayerManager manager].currentSongIndex == 0) {
        self.lastBtn.enabled = NO;
    } else {
        self.lastBtn.enabled = YES;
    }
    
    if ([SUPlayerManager manager].currentSongIndex == [SUPlayerManager manager].songList.count-1) {
        self.nextBtn.enabled = NO;
    } else {
        self.nextBtn.enabled = YES;
    }
    
    self.nameLabel.text = [SUPlayerManager manager].currentSong[@"name"];
    NSString *introduce = [NSString stringWithFormat:@"%@", [SUPlayerManager manager].currentSong[@"introduce"]];
    if (introduce.length > 0 && ![introduce isEqualToString:@"<null>"]) {
        self.desTV.attributedText = [self getHtmlStringWithString:[SUPlayerManager manager].currentSong[@"introduce"]];
    } else {
        self.desTV.attributedText = [[NSMutableAttributedString alloc] init];
    }
    [self.collectionView reloadData];
    [self.collectionView1 reloadData];
    
    NSArray *arr = [SUPlayerManager manager].currentSong[@"label"];
    if (arr.count == 0) {
        self.markView.hidden = YES;
        self.m1Label.hidden = YES;
        self.markViewHeight.constant = 0;
    } else {
        self.markView.hidden = NO;
        self.m1Label.hidden = NO;
        NSInteger a = arr.count / 3;
        NSInteger b = arr.count % 3;
        if (b > 0) {
            a += 1;
        }
        self.markViewHeight.constant =  45 * a - 15;
    }
    
    NSArray *addiArr = [self toArrayOrNSDictionary:[SUPlayerManager manager].currentSong[@"additional"]];
    if (addiArr.count == 0) {
        self.affixView.hidden = YES;
        self.m2Label.hidden = YES;
        self.affixViewHeight.constant = 0;
    } else {
        self.affixView.hidden = NO;
        self.m2Label.hidden = NO;
        NSInteger a = addiArr.count / 3;
        NSInteger b = addiArr.count % 3;
        if (b > 0) {
            a += 1;
        }
        self.affixViewHeight.constant =  45 * a - 15;
    }
    
    self.totalTimeLabel.text = [NSString convertStringWithTime:[self.player.currentSong[@"audio_num"] floatValue]];

}


- (void)alertFunc
{
    afterAlert(@"已经是最后一章了");
}
- (void)alertFunc1
{
    afterAlert(@"已经是第一章了");
}
- (void)alertFunc2
{
    [self setupUIData];
}

#pragma mark - 滑条的滑动事件 - 开始
-(void)sliderTouchDown:(UISlider *)slider{
    self.isSliding = YES;
    self.fastView.hidden = NO;
}

#pragma mark - 滑条的滑动事件 - 结束
-(void)sliderTouchUpInside:(UISlider *)slider{
    
    if (self.player.playDuration.floatValue == 0) {
        self.isSliding = NO;
        self.fastView.hidden = YES;
        return;
    }
    
    self.slider.userInteractionEnabled = NO;
    self.fastView.hidden = YES;
    CMTime changedTime = CMTimeMakeWithSeconds(self.sliderValue, slider.maximumValue);
    [self.player.player seekToTime:changedTime toleranceBefore:CMTimeMake(1, 10000) toleranceAfter:CMTimeMake(1, 10000) completionHandler:^(BOOL finished) {
        self.isSliding = NO;
        self.slider.userInteractionEnabled = YES;
        if (self.player.status == SUPlayStatusPause) {
            [self addTimer];
            [self.player startPlay];
            [self.playBtn setImage:[UIImage imageNamed:@"icon_stopImg"] forState:0];
        }
    }];
}

#pragma mark - 滑条的滑动事件 - 改变
-(void)sliderTouchValueChanged:(UISlider *)slider{
    self.sliderValue = slider.value;
    self.f1Label.text = [NSString convertStringWithTime:slider.value];
}



- (IBAction)tapHoutuiBtn:(UIButton *)sender
{
    if (self.player.playTime.floatValue <= 10) return;
    CMTime changedTime = CMTimeMakeWithSeconds(self.player.playTime.floatValue-10.0f, self.slider.maximumValue);
    [self.player.player seekToTime:changedTime toleranceBefore:CMTimeMake(1, 10000) toleranceAfter:CMTimeMake(1, 10000) completionHandler:^(BOOL finished) {

    }];
}

- (IBAction)tapQianjinBtn:(UIButton *)sender
{
    if (self.player.playTime.floatValue >= self.player.playDuration.floatValue-10) return;
    CMTime changedTime = CMTimeMakeWithSeconds(self.player.playTime.floatValue+10.0f, self.slider.maximumValue);
    [self.player.player seekToTime:changedTime toleranceBefore:CMTimeMake(1, 10000) toleranceAfter:CMTimeMake(1, 10000) completionHandler:^(BOOL finished) {

    }];
}


- (IBAction)tapLastBtn:(UIButton *)sender {
    if (!_timer) {
        [self addTimer];
    }
    [[SUPlayerManager manager] playLastSong];
    [self setupUIData];
}

- (IBAction)tapNextBtn:(UIButton *)sender {
    if (!_timer) {
        [self addTimer];
    }
    [[SUPlayerManager manager] playNextSong];
    [self setupUIData];
}

- (IBAction)tapPlayBtn:(UIButton *)sender {
    if (self.player.status == SUPlayStatusPlay) {
        [self removeTimer];
        [self.player pausePlay];
        [self.playBtn setImage:[UIImage imageNamed:@"icon_playImg"] forState:0];
    } else {
        [self addTimer];
        [self.player startPlay];
        [self.playBtn setImage:[UIImage imageNamed:@"icon_stopImg"] forState:0];
    }
    
    [self.player updateBottomView];

}

- (IBAction)tapModeBtn:(UIButton *)sender {
    if (self.player.mode == SUModeOrder) {
        self.player.mode = SUModeSingle;
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"单曲播放"] forState:0];
    } else if (self.player.mode == SUModeSingle) {
        self.player.mode = SUModeRandom;
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"随机播放"] forState:0];
    } else if (self.player.mode == SUModeRandom) {
        self.player.mode = SUModeOrder;
        [self.modeBtn setBackgroundImage:[UIImage imageNamed:@"顺序播放"] forState:0];
    }
}


- (IBAction)tapRateBtn:(UIButton *)sender {
    SURateAlertVC *vc = [SURateAlertVC new];
    __weak typeof(self) weakSelf = self;
    [vc setChangeBlock:^(NSString * rateStr) {
        [weakSelf.rateBtn setBackgroundImage:[UIImage imageNamed:[weakSelf getImageNameWithRate:rateStr]] forState:0];
    }];
    vc.tagInt = 1;
    vc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [[UIApplication sharedApplication].windows.firstObject addSubview:vc.view];
    [self addChildViewController:vc];
}

- (IBAction)tapClockBtn:(UIButton *)sender {
    SURateAlertVC *vc = [SURateAlertVC new];
    __weak typeof(self) weakSelf = self;
    [vc setClockBlock:^(NSString * str) {
        if ([str isEqualToString:@"播完当前媒体再关闭"] || [str isEqualToString:@"不开启"]) {
            weakSelf.djsLabel.hidden = YES;
            [weakSelf.timer1 invalidate];
            weakSelf.timer1 = nil;
        } else {
            [weakSelf.timer1 invalidate];
            weakSelf.timer1 = nil;
            weakSelf.timer1 = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownSet) userInfo:nil repeats:YES];
        }
    }];
    vc.tagInt = 3;
    vc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [[UIApplication sharedApplication].windows.firstObject addSubview:vc.view];
    [self addChildViewController:vc];
}

- (IBAction)tapListBtn:(UIButton *)sender {
    SURateAlertVC *vc = [SURateAlertVC new];
    __weak typeof(self) weakSelf = self;
    [vc setChoseBlock:^(NSInteger index) {
        [[SUPlayerManager manager] skipSong];
        [weakSelf setupUIData];
    }];
    vc.tagInt = 2;
    vc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [[UIApplication sharedApplication].windows.firstObject addSubview:vc.view];
    [self addChildViewController:vc];
}


#pragma mark - 定时器
- (void)addTimer {
    if (_timer) return;

    _timer = [NSTimer scheduledTimerWithTimeInterval:1.f / 20 target:self selector:@selector(refreshProgress) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes];
}

- (void)removeTimer {
    if (_timer == nil) return;

    [_timer invalidate];
    _timer = nil;
}

- (void)refreshProgress {
    
    //显示时间
    self.durationTimeLabel.text = _player.timeNow;
    if ([self.player.currentSong[@"audio_num"] floatValue] <= 0) {
        self.totalTimeLabel.text = _player.duration;
    }
    self.f2Label.text = _player.duration;
    self.slider.minimumValue = 0;
    self.slider.maximumValue = _player.playDuration.floatValue;
    
    //进度条
    float progress = _player.progress * _player.playDuration.floatValue;
    if (!self.isSliding) {
        self.slider.value = progress;
    }
    
    // 缓冲进度
    [self.cacheProgressView setProgress:_player.bufferProgress animated:NO];
    
    if (_player.bufferProgress == 1) {
        [self.slider setThumbImage:[UIImage imageNamed:@"icon_slidBtnGreen"] forState:UIControlStateNormal];
    } else {
        [self.slider setThumbImage:[UIImage imageNamed:@"icon_slidBtn"] forState:UIControlStateNormal];
    }
    
    if (self.player.status == SUPlayStatusPlay) {
        [self.playBtn setImage:[UIImage imageNamed:@"icon_stopImg"] forState:0];
    } else {
        [self.playBtn setImage:[UIImage imageNamed:@"icon_playImg"] forState:0];
    }
}



- (void)countDownSet
{
    self.djsLabel.hidden = NO;
    self.djsLabel.text = [NSString convertStringWithTime:[SUPlayerManager manager].clockLeft];
    if ([SUPlayerManager manager].clockLeft <= 0) {
        [self.timer1 setFireDate:[NSDate distantFuture]];
        self.djsLabel.hidden = YES;
    }
}

- (NSString *)getImageNameWithRate:(NSString *)rateStr {
    NSString *name = @"";
    
    if (rateStr.floatValue == 0.75) {
        name = @"倍速0.75";
    } else if (rateStr.floatValue == 1.0) {
        name = @"倍速1.0";
    } else if (rateStr.floatValue == 1.25) {
        name = @"倍速1.25";
    } else if (rateStr.floatValue == 1.5) {
        name = @"倍速1.5";
    } else if (rateStr.floatValue == 2.0) {
        name = @"倍速2.0";
    } else if (rateStr.floatValue == 2.5) {
        name = @"倍速2.5";
    } else if (rateStr.floatValue == 3.0) {
        name = @"倍速3.0";
    }
    return name;
}

- (NSMutableAttributedString *)getHtmlStringWithString:(NSString *)string {
    NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
                              NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding)};
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
    // 设置段落格式
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
    para.lineSpacing = 8;
    [attStr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, attStr.length)];
    // 设置文本的Font
    [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, attStr.length)];
    [attStr addAttribute:NSForegroundColorAttributeName value:ColorFromHex(0xFFFFFF) range:NSMakeRange(0, attStr.length)];
    return attStr;
}

- (id)toArrayOrNSDictionary:(NSString *)jsonData{
    if (jsonData != nil) {
        NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
        id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        if (jsonObject != nil){
            return jsonObject;
        }else{
            return nil;
        }
    }
    return nil;
}




#pragma delegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([collectionView isEqual:self.collectionView]) {
        return [[SUPlayerManager manager].currentSong[@"label"] count];
    } else {
        NSArray *arr = [self toArrayOrNSDictionary:[SUPlayerManager manager].currentSong[@"additional"]];
        return arr.count;
    }
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual: self.collectionView]) {
        SUMarkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"markCell" forIndexPath:indexPath];
        NSDictionary *dic = [SUPlayerManager manager].currentSong[@"label"][indexPath.row];
        cell.nameLabel.text = dic[@"label"];
        return cell;
    } else {
        SUMarkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"markCell" forIndexPath:indexPath];
        NSArray *arr = [self toArrayOrNSDictionary:[SUPlayerManager manager].currentSong[@"additional"]];
        NSDictionary *dic = arr[indexPath.row];
        cell.nameLabel.text = dic[@"title"];
        return cell;
    }
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 18;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWidth = 0;
    if ([collectionView isEqual: self.collectionView]) {
        itemWidth = (self.markView.bounds.size.width - 18*2) / 3;
    } else {
        itemWidth = (self.affixView.bounds.size.width - 18*2) / 3;
    }
    CGFloat itemHeight = 30;
    return CGSizeMake(itemWidth, itemHeight);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual: self.collectionView1]) {
        NSArray *arr = [self toArrayOrNSDictionary:[SUPlayerManager manager].currentSong[@"additional"]];
        NSDictionary *dic = arr[indexPath.row];
        
        SURateAlertVC *vc = [SURateAlertVC new];
        vc.affixTitle = dic[@"title"];
        vc.affixContent = dic[@"content"];
        vc.tagInt = 4;
        vc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        [[UIApplication sharedApplication].windows.firstObject addSubview:vc.view];
        [self addChildViewController:vc];
    } else {
        NSDictionary *dic = [SUPlayerManager manager].currentSong[@"label"][indexPath.row];
//        AudioViewController* homeOne=[[AudioViewController alloc]init];
//
//        homeOne.idString = [SUPlayerManager manager].currentSong[@"media_class_id"];
//        homeOne.title = dic[@"label"];
//        homeOne.tagString = dic[@"id"];
//        homeOne.parentName = dic[@"label"];
        
        AudioViewController* homeOne=[[AudioViewController alloc]init];
        homeOne.idString = [SUPlayerManager manager].currentSong[@"media_class_id"];
        homeOne.title = dic[@"label"];
        homeOne.tagString = dic[@"id"];
        homeOne.imageUrl = dic[@"media_image"];
        homeOne.isMenu = NO;
        homeOne.describe = dic[@"describe"];
        if (self.pushVC) {
            self.pushVC(homeOne);
        }
//        dic[@"media_mediaclass_id"]
        
//        UIViewController *controler = [UIViewController currentViewController];
//        if ([controler.class isKindOfClass:NSClassFromString(@"NewHomeViewController")]) {
//            homeOne.parentName = ((NewHomeViewController *)controler).titleString;
//        }else {
//            homeOne.parentName = controler.title;
//        }
    }
}

- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.userInteractionEnabled = YES;
        [_collectionView registerNib:[UINib nibWithNibName:@"SUMarkCell" bundle:nil] forCellWithReuseIdentifier:@"markCell"];
        [self.markView addSubview:_collectionView];
    }
    return _collectionView;
}

- (UICollectionView *)collectionView1
{
    if (!_collectionView1) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView1 = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView1.delegate = self;
        _collectionView1.dataSource = self;
        _collectionView1.backgroundColor = [UIColor clearColor];
        _collectionView1.showsVerticalScrollIndicator = NO;
        _collectionView1.scrollEnabled = NO;
        [_collectionView1 registerNib:[UINib nibWithNibName:@"SUMarkCell" bundle:nil] forCellWithReuseIdentifier:@"markCell"];
        [self.affixView addSubview:_collectionView1];
    }
    return _collectionView1;
}

@end
